<template>
	<uni-nav-bar
		:title="finProps.title"
		:statusBar="finProps.statusBar"
		:backgroundColor="finProps.backgroundColor"
		:leftText="finProps.leftText"
		:leftIcon="finProps.leftIcon"
		@clickLeft="clickLeft"
	></uni-nav-bar>
</template>

<script>
import Hybrid from '@/utils/Hybrid.js';
export default {
	props: {
		webview: {
			type: Object
		},
		navbarProps: {
			type: Object
		},
		customClickLeft: false
	},
	data() {
		return {
			defaultProps: {
				title: '标题',
				leftText: '',
				statusBar: true,
				backgroundColor: '#ccc',
				leftIcon: 'arrowleft'
			},
			fromH5Props: {},
			hybrid: null
		};
	},
	computed: {
		finProps() {
			return Object.assign(this.defaultProps, this.navbarProps, this.fromH5Props);
		}
	},
	created() {
		setTimeout(() => {
			if (!this.webview) {
				return console.warn('webview 不存在');
			}
			this.hybrid = new Hybrid(this.webview);

			this.hybrid.setHeader((data, callback) => {
				this.fromH5Props = Object.assign({}, data);
				callback({
					code: 0,
					data: '哈哈哈',
					message: 'success'
				});
			});
		});
	},
	mounted() {},
	methods: {
		clickLeft() {
			!this.customClickLeft && uni.navigateBack();
			this.$emit('clickLeft');
		}
	}
};
</script>

<style lang="scss"></style>
